package hp.com.servlet.CartDataServlet;

import hp.com.service.CartDataService;
import hp.com.service.impl.CartDataServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/DeleteCartData")
public class BuyCarDeleteServlet extends HttpServlet {
    private CartDataService cartDataService = new CartDataServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        CartDataService cs = new CartDataServiceImpl();
        int deleteId = Integer.parseInt(req.getParameter("itemId"));
        try
        {cs.DeleteCartData(deleteId);}catch(Exception e){
            e.printStackTrace();
        }
        resp.sendRedirect(req.getContextPath()+"/Cart");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
